//**********************************************************
//    File Name: FrmHCWSearch.cs
//    Author: Team Motif
//    Date Created : 04/13/2007
//    Current Owner: Team Motif 
//                                                                            
//    Purpose: 
//    To search and view the profile for the particular Home Care Worker.
//
//	  Copyright 2007
//**********************************************************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace Elderhealth
{
    public partial class FrmHCWSearch : Form
    {
        public FrmHCWSearch()
        {
            InitializeComponent();
        }
        private void Search_Click(object sender, EventArgs e)
        {
            //Clear the results of the previous records of DataGridView
            for (int iCntr = HCWDisplaydataGrid.RowCount - 1; iCntr >= 0; iCntr = iCntr - 1)
            {
                HCWDisplaydataGrid.Rows.RemoveAt(iCntr);
            }

            //Catch Error if both firstname and Last name is Empty
            if (String.IsNullOrEmpty(HCWFName.Text) && String.IsNullOrEmpty(HCWLName.Text))
            {
                MessageBox.Show("Please provide a valid First Name or a Last Name");
            }
            else
            {
                //Populate the DataGridView
                PopulateDataGridView();
            }
        }

        /// <summary>
        /// Display the list of Home Care Worker(s)
        /// </summary>
        private void PopulateDataGridView()
        {
            ArrayList HCWList;
            HCWList = Library.HomeCareWorker.GetWorkerList(HCWFName.Text, HCWLName.Text);
            Library.HomeCareWorker HCWdetail;
            if (HCWList.Count == 0)
            {
                NoRecord.Visible = true;
            }
            else
            {
                for (int iCntr = 0; iCntr < HCWList.Count; iCntr++)
                {
                    HCWdetail = (Library.HomeCareWorker)HCWList[iCntr];
                    String Name = HCWdetail.GetFirstName() + " " + HCWdetail.GetLastName();
                    String Add = HCWdetail.GetCity() + "," + HCWdetail.GetState();
                    HCWDisplaydataGrid.Rows.Add(0, Name, Add, HCWdetail.GetDateOfBirth().ToShortDateString(), HCWdetail.GetPhoneNumber1().ToString(), HCWdetail.GetUserID().ToString());
                }
                NoRecord.Visible = false;
            }
        }

        /// <summary>
        /// User decides to cancel the task in hand and hence wishes to close the form.
        /// </summary>
        
        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Display the details for the Home Care Worker selected.
        /// </summary>
        private void HCWDisplaydataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            long TmpHCWID;
            int TmpSelRow = HCWDisplaydataGrid.SelectedCells[0].RowIndex;
            String SelectedRowOutput = HCWDisplaydataGrid.Rows[TmpSelRow].Cells[5].Value.ToString();
            TmpHCWID = long.Parse(SelectedRowOutput);
            this.Close();
            FrmViewHCWScheduleProfile frm = new FrmViewHCWScheduleProfile(TmpHCWID);
            frm.Show();
        }

        /// <summary>
        /// Clear the form.
        /// </summary>
        private void Clear_Click(object sender, EventArgs e)
        {
            //Clear the results of the previous records of DataGridView
            for (int iCntr = HCWDisplaydataGrid.RowCount - 1; iCntr >= 0; iCntr = iCntr - 1)
            {
                HCWDisplaydataGrid.Rows.RemoveAt(iCntr);
            }
            HCWFName.Text = "";
            HCWLName.Text = "";
            NoRecord.Visible = false;
        }

        
    }
}